package cn.edu.gdu.quizpractice.dao;

import cn.edu.gdu.quizpractice.entity.Manager;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Optional;

/**
 * @Author: Aubery
 * @Date: 2025-01-19-14:54
 * @Description:
 */


@Mapper
public interface ManagerDao extends BaseMapper<Manager> {

    @Select("select email from t_manager where email = #{email}")
    boolean existsByEmail(String email);

    @Select("select telephone from t_manager where telephone = #{telephone}")
    boolean existsByTele(String telephone);

    @Select("select * from t_manager where telephone = #{telephone}")
    Manager findByTeleAndPassword(String telephone, String password);

    @Select("select * from t_manager")
    List<Manager> findAll();

    @Select("select * from t_manager where telephone = #{telephone}")
    Optional<Manager> findByTele(String telephone);

    /**
     * 添加管理员
     * @param entity
     * @return
     * @description 排除id字段
     */
    @Insert("insert into t_manager(name,telephone,password,email,status,type) values(#{name},#{telephone},#{password},#{email},#{status},#{type})")
    boolean add(Manager entity);

    @Delete("delete from t_manager where telephone = #{telephone}")
    boolean deleteByTele(String telephone);

    @Update("update t_manager set name = #{name},telephone = #{telephone}," +
            "password = #{password},email = #{email},status = #{status}," +
            "type = #{type} where telephone = #{telephone}")
    boolean updateByTele(Manager manager);

    @Update("update t_manager set password = #{password} where telephone = #{telephone}")
    boolean updatePwd(String telephone, String password);

    @Select("select password from t_manager where telephone = #{telephone}")
    String findPwdByTele(String telephone);

    @Update("update t_manager set email = #{email} where telephone = #{telephone}")
    boolean updateEmail(String telephone, String email);
}
